package com.atguigu.gmall.pay.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;

import javax.annotation.PostConstruct;


@Slf4j
@Configuration
public class MQConfig {

    @Autowired
    RabbitTemplate rabbitTemplate;

    @PostConstruct
    public void init(){
        rabbitTemplate.setConfirmCallback((correlationData,flag,msg)->{
            log.error(correlationData.getId()+msg);
        });
        //交换机发送给队列的失败回调
        //Message var1, int var2, String var3, String var4, String var5
        rabbitTemplate.setReturnCallback((message, code,txt,exchange,routerKey)->{
            log.error("消息没有到达队列 状态码：{}，错误内容：{}，交换机：{}，路由键：{}",code,new String(message.getBody()),exchange,routerKey);
        });
    }
}

